package com.ld.wms.business.material.controller;


import com.ld.wms.business.material.service.MaterialTypeService;
import com.ld.wms.business.material.vo.req.MaterialTypeFieldReqVo;
import com.ld.wms.business.material.vo.req.MaterialTypeReqVo;
import com.ld.wms.business.material.vo.resp.MaterialTypeFieldRespVo;
import com.ld.wms.business.material.vo.resp.MaterialTypeRespVo;
import com.ld.wms.common.ResultResponse;
import com.ld.wms.common.vo.GenerateListVo;
import com.ld.wms.common.vo.GeneratePageListVo;
import com.ld.wms.sysenum.ResultResponseEnum;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 物料类型数据 前端控制器
 * </p>
 *
 * @author wangfeng
 * @since 2025-02-24
 */
@Slf4j
@Tag(name = "物料类型相关接口")
@RestController
public class MaterialTypeController {

    @Autowired
    private MaterialTypeService materialTypeService;

    @PostMapping("/api/wms/materialType/add")
    @Operation(summary = "添加")
    public ResultResponse<ResultResponseEnum> add(
            @RequestBody MaterialTypeReqVo reqVo
    ) {
        materialTypeService.add(reqVo);
        return ResultResponse.success();
    }

    @PostMapping("/api/wms/materialType/update")
    @Operation(summary = "修改")
    public ResultResponse<ResultResponseEnum> updateById(
            @RequestBody MaterialTypeReqVo reqVo
    ) {
        materialTypeService.updateById(reqVo);
        return ResultResponse.success();
    }

    @GetMapping("/api/wms/materialType/getPageList")
    @Operation(summary = "物料类型列表(下拉框可用,下拉框传9999)")
    public ResultResponse<GeneratePageListVo<MaterialTypeRespVo>> getPageList(
            @RequestParam(required = false, defaultValue = "1") Integer current,
            @RequestParam(required = false, defaultValue = "10") Integer size
    ) {
        GeneratePageListVo<MaterialTypeRespVo> allList = materialTypeService.getPageList(current, size);
        return ResultResponse.success(allList);
    }

    @GetMapping("/api/wms/materialType/getMaterialTypeFieldDetails")
    @Operation(summary = "根据物料类型获取对应字段id")
    public ResultResponse<MaterialTypeFieldRespVo> getMaterialTypeFieldDetails(
            @RequestParam Long materialTypeId
    ) {
        MaterialTypeFieldRespVo materialTypeFieldRespVo = materialTypeService.getMaterialTypeFieldDetails(materialTypeId);
        return ResultResponse.success(materialTypeFieldRespVo);
    }

    @PostMapping("/api/wms/materialType/configMaterialTypeField")
    @Operation(summary = "配置类型字段")
    public ResultResponse<ResultResponseEnum> configMaterialTypeField(
            @RequestBody MaterialTypeFieldReqVo reqVo
    ) {
        materialTypeService.configMaterialTypeField(reqVo);
        return ResultResponse.success();
    }

}

